package com.malamute.system.entity;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.struts2.json.annotations.JSON;

import com.malamute.core.entity.BaseEntity;

/**
 * @description 树节点
 * @version v1.0
 */

@Entity
@Table(name = "T_SYS_TREENODE")
public class TreeNode extends BaseEntity {
	private String url;// 连接地址
	private String text;// 显示文字
	private String target;// 目标页面
	private String iconCls; // 现实图标
	private boolean isLeaf = false;// 是否树叶
	private boolean isChecked = false;// 是否有选择
	private boolean isOpen = true;

	@Enumerated(value = EnumType.ORDINAL)
	private NodeType type = NodeType.FOLDEN;// 节点类型

	@ManyToOne(targetEntity = TreeNode.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "pid")
	private TreeNode belongTo;// 归属
	@Transient
	private Integer pId;
	private Tree tree;

	@OneToMany(targetEntity = TreeNode.class, cascade = { CascadeType.ALL }, mappedBy = "belongTo")
	private Set<TreeNode> children; // 子节点

	public String getUrl() {
		return url;
	}

	public boolean isLeaf() {
		return isLeaf;
	}

	public void setLeaf(boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@JSON(name = "name")
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String getIconCls() {
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	public boolean isChecked() {
		return isChecked;
	}

	public void setChecked(boolean isChecked) {
		this.isChecked = isChecked;
	}

	public boolean isOpen() {
		return isOpen;
	}

	public void setOpen(boolean isOpen) {
		this.isOpen = isOpen;
	}

	public TreeNode getBelongTo() {
		return belongTo;
	}

	public void setBelongTo(TreeNode belongTo) {
		this.belongTo = belongTo;
	}

	public Set<TreeNode> getChildren() {
		return children;
	}

	public void setChildren(Set<TreeNode> children) {
		this.children = children;
	}

	public NodeType getType() {
		return type;
	}

	public void setType(NodeType type) {
		this.type = type;
	}

	public Integer getpId() {
		if (belongTo != null) {
			setpId(belongTo.getId());
		}
		return pId;
	}

	public void setpId(Integer pId) {
		this.pId = pId;
	}

}
